﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using TracNghiem.Models;

namespace TracNghiem.Controllers
{
    public class HomeController : Controller
    {
        AccountModel AccountModel = new AccountModel();
        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";

            return View();
        }

        [HttpPost]
        public ActionResult Logon(AccountModel Account)
        {
            if (ModelState.IsValid)
            {
                if (AccountModel.checkAccount(Account) > 0)
                {
                    FormsAuthentication.SetAuthCookie(Account.username, Account.RememberMe);
                    return RedirectToAction("Index");
                }
            }
            TempData["msg"] = "Tên đăng nhập hoặc mật khẩu không chính xác!";            
            return RedirectToAction("Index");
        }
        public ActionResult LogOff()
        {
            FormsAuthentication.SignOut();
            //Session.Clear();
            Session.Abandon();
            return RedirectToAction("Index");
        }
    }
}
